#This file handles all file IO.
#Provides methods for returning a stream for each of the datasets.
#Each dataset can be opened in either read mode or write mode.

import sys
import io

from Resources.config import DEFAULT_DATASET_FILE_PATH, DEFAULT_TRAINING_FILE_PATH, DEFAULT_TESTING_FILE_PATH, DEFAULT_RESULTS_FILE_PATH, READ_MODE, WRITE_MODE

def openFile(filePath, fileMode):
	return io.open(filePath, fileMode)
	
def openDataSetFile(fileMode):
	filePath = None
	if(len(sys.argv)>1):
		filePath = sys.argv[1]
	if(filePath is None or len(filePath)==0):
		filePath = DEFAULT_DATASET_FILE_PATH
	return io.open(filePath, fileMode)

def openTrainingFile(fileMode):
	filePath = None
	if(len(sys.argv)>2):
		filePath = sys.argv[2]
	if(filePath is None or len(filePath)==0):
		filePath = DEFAULT_TRAINING_FILE_PATH
	return io.open(filePath, fileMode)

def openTestingFile(fileMode):
	filePath = None
	if(len(sys.argv)>3):
		filePath = sys.argv[3]
	if(filePath is None or len(filePath)==0):
		filePath = DEFAULT_TESTING_FILE_PATH
	return io.open(filePath, fileMode)
	
def openResultsFile(fileMode):
	filePath = None
	if(len(sys.argv)>4):
		filePath = sys.argv[4]
	if(filePath is None or len(filePath)==0):
		filePath = DEFAULT_RESULTS_FILE_PATH
	return io.open(filePath, fileMode)